//
// Created by benxb on 2021/11/11.
//

#include <gtest/gtest.h>
#include <storage/disk/column_storage.h>

namespace benxdb {

const std::string data_file = "/home/ubuntu/benxdb/test/storage/test.data_";
const std::string map_file = "/home/ubuntu/benxdb/test/storage/test_map.data_";

TEST(ColumnStorageTest, WriteSinglePageTest) {
    remove(data_file.data());
    remove(map_file.data());
    std::string data = "Hello world";
    ColumnStorage storage(data_file);
    int64_t page_id = storage.WritePage(data.data(), data.size());
    std::string out;
    storage.ReadPage(page_id, out);
    EXPECT_EQ(out, data);
}

TEST(ColumnStorageTest, WriteManyPageTest) {
    remove(data_file.data());
    remove(map_file.data());
    std::vector<std::string> data_vec = {"Hello world", "My Name Is", "Li Hua"};
    std::vector<int64_t> page_ids;
    ColumnStorage storage(data_file);
    for (int i = 0; i < data_vec.size(); i++) {
        int64_t page_id = storage.WritePage(data_vec[i].data(), data_vec[i].size());
        page_ids.push_back(page_id);
    }
    std::string out;
    for (int i = 0; i < data_vec.size(); i++) {
        storage.ReadPage(page_ids[i], out);
        EXPECT_EQ(out, data_vec[i]);
        out.clear();
    }
}

}